{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from kmeans_class import *\n",
    "import pandas as pd\n",
    "from sklearn.cluster import KMeans\n",
    "from sklearn.model_selection import GridSearchCV,ParameterGrid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "****************************** output0 ******************************\n",
      "       模型及参数:  KMeans(n_clusters=3)\n",
      "Homogeneity Score         (均一性):  0.5549512618208781\n",
      "Completeness Score        (完整性):  0.8555973568749705\n",
      "V-Measure Score           (V量):  0.6732342671709858\n",
      "Adjusted Rand Score       (调整后兰德指数):  0.6800093729110801\n",
      "Adjusted Mutual Info Score(调整后的共同信息):  0.6721202165706559\n",
      "Calinski Harabasz Score:  (方差比指数)  1113.8685257899092\n",
      "Silhouette Score          (轮廓分数):  0.664093045850933\n",
      "****************************** output1 ******************************\n",
      "       模型及参数:  KMeans(n_clusters=4)\n",
      "Homogeneity Score         (均一性):  0.7457399410842509\n",
      "Completeness Score        (完整性):  0.8448372457330804\n",
      "V-Measure Score           (V量):  0.7922015769878176\n",
      "Adjusted Rand Score       (调整后兰德指数):  0.8149667143643013\n",
      "Adjusted Mutual Info Score(调整后的共同信息):  0.7912849716244518\n",
      "Calinski Harabasz Score:  (方差比指数)  1105.0422300885427\n",
      "Silhouette Score          (轮廓分数):  0.6458696656931824\n",
      "****************************** output2 ******************************\n",
      "       模型及参数:  KMeans(n_clusters=5)\n",
      "Homogeneity Score         (均一性):  0.7386945806216931\n",
      "Completeness Score        (完整性):  0.689225067088799\n",
      "V-Measure Score           (V量):  0.7131029014180821\n",
      "Adjusted Rand Score       (调整后兰德指数):  0.697755576113046\n",
      "Adjusted Mutual Info Score(调整后的共同信息):  0.7115797134398348\n",
      "Calinski Harabasz Score:  (方差比指数)  1130.6232287800535\n",
      "Silhouette Score          (轮廓分数):  0.6589950531796837\n",
      "****************************** output3 ******************************\n",
      "       模型及参数:  KMeans(init='random', n_clusters=3)\n",
      "Homogeneity Score         (均一性):  0.5549512618208781\n",
      "Completeness Score        (完整性):  0.8555973568749705\n",
      "V-Measure Score           (V量):  0.6732342671709858\n",
      "Adjusted Rand Score       (调整后兰德指数):  0.6800093729110801\n",
      "Adjusted Mutual Info Score(调整后的共同信息):  0.6721202165706559\n",
      "Calinski Harabasz Score:  (方差比指数)  1113.8685257899094\n",
      "Silhouette Score          (轮廓分数):  0.664093045850933\n",
      "****************************** output4 ******************************\n",
      "       模型及参数:  KMeans(init='random', n_clusters=4)\n",
      "Homogeneity Score         (均一性):  0.7457399410842511\n",
      "Completeness Score        (完整性):  0.8448372457330806\n",
      "V-Measure Score           (V量):  0.7922015769878177\n",
      "Adjusted Rand Score       (调整后兰德指数):  0.8149667143643013\n",
      "Adjusted Mutual Info Score(调整后的共同信息):  0.791284971624452\n",
      "Calinski Harabasz Score:  (方差比指数)  1105.0422300885427\n",
      "Silhouette Score          (轮廓分数):  0.6458696656931824\n",
      "****************************** output5 ******************************\n",
      "       模型及参数:  KMeans(init='random', n_clusters=5)\n",
      "Homogeneity Score         (均一性):  0.7374283804166837\n",
      "Completeness Score        (完整性):  0.6875822641180962\n",
      "V-Measure Score           (V量):  0.7116335269163933\n",
      "Adjusted Rand Score       (调整后兰德指数):  0.6984178443876293\n",
      "Adjusted Mutual Info Score(调整后的共同信息):  0.7101030817312814\n",
      "Calinski Harabasz Score:  (方差比指数)  1130.60631450395\n",
      "Silhouette Score          (轮廓分数):  0.6590111551034573\n"
     ]
    }
   ],
   "source": [
    "df = pd.read_excel('test4.xlsx')\n",
    "data = df.drop('TRUE VALUE', axis=1)\n",
    "labels = df['TRUE VALUE']\n",
    "\n",
    "# 测试kmeans模型\n",
    "GeoKmeans = GeoKmeans()\n",
    "kmeans=KMeans()\n",
    "kmeans_dict = GeoKmeans.read_para()\n",
    "output = GeoKmeans.KmeansGridsearch(kmeans,data,kmeans_dict)\n",
    "\n",
    "# kmeans测试结果\n",
    "for i in range(len(output)):\n",
    "    GeoKmeans.get_marks(output[i], data=data, labels=labels, name=\"output\" + str(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
